% equally spaced traps

x = -1:0.001:1;
y = -1:0.001:1;

n = 5;

N = 1:n;

x0 = real(exp(2*pi*1i.*N./n));
y0 = imag(exp(2*pi*1i.*N./n));

v = zeros(length(x),length(y));
G = zeros(length(x),length(y));

D = 1;
epsilon = 0.1;

for i = 1:length(x)
    for j = 1:length(y)
        r = sqrt(x(i)*x(i) + y(j)*y(j));
        if r <= 1
            for k = 1:n
                G(i,j) = G(i,j) - 1/pi * log(sqrt((x(i)-x0(k))^2 + (y(j)-y0(k))^2)) + r^2/(4*pi) - 1/(8*pi);
            end
            v(i,j) = 1 / (D*n) * (-log(epsilon*n/2) + n/8 - pi*G(i,j));
            if v(i,j) < 0
                v(i,j) = 0;
            end
        end
    end
end

surf(x,y,v,'Edgecolor','none');
axis equal;